package com.smscenter.server.core.ztsms;

import com.smscenter.server.core.IQuery;
import com.zeus.base.privilege.utils.ArithUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ShanFei on 2017-02-16.
 */
public class ZtSmsQuery implements IQuery {
    @Override
    public String queryBalance(Map<String, Object> params) throws Exception {
        return null;
    }

    @Override
    public String queryCollect(Map<String, Object> params) throws Exception {
        return null;
    }

    @Override
    public String querySendRecordInfo(Map<String, Object> params) throws Exception {
        return null;
    }

    @Override
    public String queryBalanceV2(Map<String, Object> params) throws Exception {
        String url ="http://www.ztsms.cn/balanceN.do";
        String username =params.get("loginName").toString();//内容
        String password =params.get("loginPassword").toString();//密码
        String unitPrice = params.get("unitPrice").toString();//单价
        String tkey =TimeUtil.getNowTime("yyyyMMddHHmmss");
        String param="url="+url+"&username="+username+"&password="+MD5Gen.getMD5(MD5Gen.getMD5(password)+tkey)+"&tkey="+tkey;
        String ret=HttpRequest.sendPost(url, param);//sendPost or sendGet  即get和post方式
        String returnMsg = "";
        if (ret.equals("-1")){
        	throw  new Exception("用户名或者密码不正确");
//            returnMsg = "{'balance':'0','money':'0','code':'false','message':'用户名或者密码不正确'}";
        }else if (ret.equals("-2")){
        	throw  new Exception("tkey不正确");
//            returnMsg = "{'balance':'0','money':'0','code':'false','message':'tkey不正确'}";
        }else if (ret.equals("-3")){
        	throw  new Exception("用户不存在或用户停用");
//            returnMsg = "{'balance':'0','money':'0','code':'false','message':'用户不存在或用户停用'}";
        }else{
            Double money = ArithUtil.mul(Double.parseDouble(ret),Double.parseDouble(unitPrice));
            returnMsg = "{'balance':'"+ret+"','money':'"+money+"','code':'true','message':''}";
        }
        return returnMsg;
    }
    
    public static void main(String[] args) throws Exception {
    	ZtSmsQuery x = new ZtSmsQuery();
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("loginName", "dlguangdaxx");
    	params.put("loginPassword", "Guangdaxxfy56");
    	params.put("unitPrice", "0.1");
    	x.queryBalanceV2(params);
	}
}
